--pieces
local base = piece("base")
  body = piece("hull")
	  local chimney1, chimney2 = piece("chimney1", "chimney2")
	  local wake1, wake2 = piece("wake1", "wake2")    
    local turret1, barrel1, firepoint1 = piece("turret1", "barrel1", "firepoint1")
    local turret2, barrel2, firepoint2 = piece("turret2", "barrel2", "firepoint2")
    local turret3, barrel3, firepoint3 = piece("turret3", "barrel3", "firepoint3")
    local tube4, firepoint4a, firepoint4b = piece("tube4", "firepoint4a", "firepoint4b")
    local tube5, firepoint5a, firepoint5b = piece("tube5", "firepoint5a", "firepoint5b")

scriptParams = {
  smokePieces = { body },
  enginePieces = { chimney1, chimney2 },
  smokeDelay = 300,
  maxRockAngleX = 5,
  maxRockAngleZ = 1,
  rockOnMove = false,

  weapons = {
    [1] = {
	--turret, sleeve, barrel, firepoint = 
      turretTurnSpeed = 70,
      sleeveTurnSpeed = 50,
      barrelRecoil = 3,
      rockForce = 200,
      minPitch = -20,
      restores = true,
      cegID = 1,
    },
    [2] = {
      turretTurnSpeed = 70,
      sleeveTurnSpeed = 50,
      barrelRecoil = 3,
      rockForce = 200,
      minPitch = -20,
      restores = true,
      cegID = 1,
    },
    [3] = {
      turretTurnSpeed = 70,
      sleeveTurnSpeed = 50,
      barrelRecoil = 3,
      rockForce = 200,
      minPitch = -20,
      restores = true,
      cegID = 1,
    },    
    [4] = {
      turretTurnSpeed = 50,
      sleeveTurnSpeed = 50,
	    minPitch = -20,
	    restores = true,      
    },
    [5] = {
      turretTurnSpeed = 50,
      sleeveTurnSpeed = 50,
	    minPitch = -20,
	    restores = true,      
    },    
  }  
}

include "pre_scripts.lua"

setWeaponPieces(1, turret1, barrel1, barrel1, firepoint1)
setWeaponPieces(2, turret2, barrel2, barrel2, firepoint2)
setWeaponPieces(3, turret3, barrel3, barrel3, firepoint3)
setWeaponPieces(4, tube4, firepoint4a, firepoint1, {firepoint4a, firepoint4b} )
setWeaponPieces(5, tube5, firepoint1, firepoint1, {firepoint5a, firepoint5b} )

include "scripts.lua"

local scriptCreate = script.Create
function script.Create()
  scriptCreate()
  Show (chimney1)
  Show (chimney2)
end

function script.Killed (recentDamage, maxHealth)
  local severity = recentDamage / maxHealth
  
  Explode (body, SFX.NONE)
  if (severity <= 0.25) then
	  return 1
  elseif (severity <= 0.50) then
	  return 2
  else
  	return 3
  end
end